﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AncientLand.Service.Entity;
using AncientLand.Service.IBiz;
using AncientLand.Service.IDa;

namespace AncientLand.Biz
{
   public class ActivitiesBiz:IActivitiesBiz
    {
        private readonly IActivitiesRepository _repository;
        private readonly ICommit _commitAble;
        public ActivitiesBiz(IActivitiesRepository repository, ICommit commitAable)
        {
            this._repository = repository;
            this._commitAble = commitAable;
        }  

       public IEnumerable<Activities> GetAll()
       {
           return _repository.GetAll();
       }

       public Activities GetById(int id)
       {
           return _repository.GetById(id);
       }

       public void Create(Activities news)
       {
           _repository.Add(news);
           Save();
       }

       public void Update(Activities news)
       {
           _repository.Update(news);
           Save();
       }

       public void Delete(int id)
       {
           var activitie = _repository.GetById(id);
           _repository.Delete(activitie);
           Save();
       }

       public void Save()
       {
           _commitAble.Commit();
       }

       public IEnumerable<Activities> GetItemsByPages(out int totalRecord, int? pageIndex = 1, int? pageSize = 10, string orderFiled = "ID")
       {
           return _repository.GetItemsByPages(pageIndex.GetValueOrDefault(), pageSize.GetValueOrDefault(), orderFiled, out totalRecord);
       }
    }
}
